<?php
namespace app\common\model;

use Helper\Acceptance;
use think\Db;

class UserAddressModel extends BaseModel
{
    protected $name = 'user_address'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改

    /*读取器*/
    protected function getAddressTextAttr($value, $data)
    {
        $areaList           = cache('area');
        $address[] = $areaList[$data['prov_id']];
        $address[] = $areaList[$data['city_id']];
        $address[] = $areaList[$data['dist_id']];
        return implode(' ',$address);
    }

    /*修改器*/

    /**
     * 设置默认地址
     * @param $uid
     * @param $addressId
     */
    public function setDefault($uid,$addressId){
        $this->where('uid', $uid)->setField(['is_default' => 0]);
        $this->where('address_id', $addressId)->update(['is_default' => 1]);
        return true;
    }

}




